﻿// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/MonthView/MonthView.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            initYearMonthList();
            YearList().selectedIndex = currentYear - 1900;
            MonthList().selectedIndex = currentMonth;
            initMonthTable();
            drawCld(currentYear, currentMonth);
            bindCellClickEvent();
            currentView = "month";

            document.getElementById("dayviewbar").style.display = "inline";
            document.getElementById("monthviewbar").style.display = "none";
            document.onkeyup = keyEvent;
        },
        unload: function () {
            //CalendarApp.removeAppBars();
        },

        updateLayout: function (element, viewState, lastViewState) {
            /// <param name="element" domElement="true" />

            // TODO: Respond to changes in viewState.
        }
    });

    function keyEvent(event) {
        if (currentView === "month") {
            var key = event.keyCode;
            if (key === 37 || key === 33 || key === 109 || key === 189) {
                pushBtm('MU');
            }
            if (key === 39 || key === 34 || key === 107 || key === 187) {
                pushBtm('MD');
            }
            if (key === 27 || key === 36) {
                pushBtm();
            }
        }
    }
})();